package course.java.hr;

import static org.junit.Assert.*;

import java.util.Collection;

import org.junit.*;
import static org.mockito.Mockito.*;

public class CompanyTest
{
	Company comp;
	String cname = "Acme";
	String taxid = "12-3456789";
	
	@Before
	public void setup()
	{
		comp = new Company(cname, taxid);
	}
	
	@Test
	public void testCompanyHire()
	{
		Employee e1 = new Employee("Test Emp1", "123-45-6789");
		Employee e2 = new Employee("Test Emp2", "123-45-6788");
		
		Company c2 = new Company("IT Dept", "12-3334444");
		c2.hire(e1, e2);
		
		comp.hire(c2);
		
		Collection employees = comp.getEntities();
		assertEquals (1, employees.size());
		assertEquals (2, c2.getEntities().size());
	}
	
	@Test
	public void testCompanyPay()
	{
		Employee e1 = new Employee("Test Emp1", "123-45-6789");
		Employee e2 = new Employee("Test Emp2", "123-45-6788", 100);
		
		Company c2 = new Company("IT Dept", "12-3334444");
		c2.hire(e1, e2);
		
		comp.hire(c2);
		
		comp.pay();
		assertEquals (100, e2.getYtdSalary(), .001);
	}

	@Test
	public void testCompanyMockitoPay()
	{
		TaxableEntity te1 = mock(TaxableEntity.class);
		when(te1.pay()).thenReturn(50.0f);
		
		TaxableEntity te2 = mock(TaxableEntity.class);
		when(te2.pay()).thenReturn(150.0f);
		
		comp.hire(te1,te2);
		
		float total = comp.pay();
		assertEquals(200.0f, total, .001);
		
		verify(te1).pay();
		
	}
	
	
	//@Test
	public void testCompanyMockPay()
	{
		class MockTe extends TaxableEntity
		{
			boolean paycalled = false;
			public MockTe(String name, String taxId)
			{
				super(name, taxId);
			}

			public float pay() {paycalled = true; return 0;}

			@Override
			protected String getTaxIdRegex()
			{
				return "";
			}
		}
		
		MockTe e1 = new MockTe("Test Emp1", "123-45-6789");
		MockTe e2 = new MockTe("Test Emp2", "123-45-6788");
		
		Company c2 = new Company("IT Dept", "12-3334444");
		c2.hire(e1, e2);
		
		comp.hire(c2);
		assertEquals (24, comp.pay(), .001);
		assertTrue (e1.paycalled);
		assertTrue (e2.paycalled);
		
	}

	


}
